package com.mingqi.enetconnected.primary.worktable;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mingqi.enetconnected.R;
import com.mingqi.enetconnected.base.BaseFragment;
import com.mingqi.enetconnected.primary.worktable.adapter.MyWorkTypeAdapter;
import com.mingqi.enetconnected.util.img.GlideImageLoader;
import com.mingqi.enetconnected.util.resource.ResourceUtils;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import butterknife.BindView;

/**
 * 工作台模块
 * Created by li on 2018/7/30.
 * WeChat 18571658038
 * author LiWei
 */

public class WorkTableFragment extends BaseFragment {

    @BindView(R.id.ban_ad)
    Banner mBanAd;
    @BindView(R.id.rv_work)
    RecyclerView mRvWork;

    private int[] workImgs = {R.drawable.ic_schedule_manage,R.drawable.ic_hostory_task,R.drawable.ic_loot_assignment_pool,R.drawable.ic_invite_code,
            R.drawable.ic_employee_ud_id,R.drawable.ic_data_download,R.drawable.ic_task_analyze,R.drawable.ic_template_setting};

    private int[] workTitles = {R.string.schedule_manage,R.string.hostory_task,R.string.loot_assignment_pool,R.string.invite_code,
                    R.string.employee_ud_id,R.string.data_download,R.string.task_analyze,R.string.template_setting};


    @Override
    protected View bindView(ViewGroup container) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.fragment_work_table, container,false);
        return view;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

        initBanner();
        initGridView();
    }

    private void initGridView() {

        mRvWork.setLayoutManager(new GridLayoutManager(mContext,3));

        final List<Map<String,Integer>> workTableList = new ArrayList<>();
        for (int i = 0; i < 8; i++) {

            Map<String,Integer> map = new HashMap<>();
            map.put("img",workImgs[i]);
            map.put("title",workTitles[i]);

            workTableList.add(map);
        }

        MyWorkTypeAdapter adapter = new MyWorkTypeAdapter(workTableList);
        mRvWork.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                Toast.makeText(mContext, "" + ResourceUtils.getString(workTableList.get(position).get("title")), Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initBanner() {

        List<Integer> images = new ArrayList<>();
        for (int i = 0; i < 5; i++) {

            images.add(R.drawable.welcome_bg);
        }
        mBanAd.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        mBanAd.setImageLoader(new GlideImageLoader());
        mBanAd.setImages(images);
        mBanAd.setBannerAnimation(Transformer.Default);
        mBanAd.isAutoPlay(true);
        mBanAd.setIndicatorGravity(BannerConfig.CENTER);
        mBanAd.start();

        mBanAd.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {

                Toast.makeText(mContext, "点击了第" + (position + 1) + "个" , Toast.LENGTH_SHORT).show();
            }
        });
    }
}
